home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / awt / test / scrollba.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  2.2 KB  |  76 lines

  1. /*
  2.  * @(#)ScrollbarTest.java    1.2 95/08/16 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. import java.awt.*;
  21.  
  22. class ScrollablePaintCanvas extends Canvas {
  23.     int tx = 20;
  24.     int ty = 100;
  25.     static final int SIZE = 500;
  26.  
  27.     public void paint(Graphics g) {
  28.     g.translate(-tx, -ty);
  29.     for (int i = 0 ; i < 200 ; i += 20) {
  30.         g.drawOval(i, i, SIZE - 2*i, SIZE - 2*i);
  31.     }
  32.     g.setColor(Color.yellow);
  33.     g.drawLine(0, SIZE/2, SIZE, SIZE/2);
  34.     g.drawLine(SIZE/2, 0, SIZE/2, SIZE);
  35.  
  36.     g.setColor(Color.red);
  37.     g.fillOval(SIZE/2 - 20, SIZE/2 - 20, 40, 40);
  38.     }
  39. }
  40.  
  41. /**
  42.  * A test of a Container with BorderLayout.
  43.  */
  44. public class ScrollbarTest extends Frame {
  45.     Scrollbar vert;
  46.     Scrollbar horz;
  47.     ScrollablePaintCanvas cv;
  48.  
  49.     public ScrollbarTest() {
  50.     super("ScrollbarTest");
  51.     add("Center", cv = new ScrollablePaintCanvas());
  52.     add("East", vert = new Scrollbar(Scrollbar.VERTICAL, cv.ty, 100, 0, ScrollablePaintCanvas.SIZE));
  53.     add("South", horz = new Scrollbar(Scrollbar.HORIZONTAL, cv.tx, 100, 0, ScrollablePaintCanvas.SIZE));
  54.     reshape(100, 200, 300, 250);
  55.     show();
  56.     }
  57.  
  58.     public boolean handleEvent(Event evt) {
  59.     if (evt.target == vert) {
  60.         cv.ty = ((Integer)evt.arg).intValue();
  61.         cv.repaint();
  62.         return true;
  63.     }
  64.     if (evt.target == horz) {
  65.         cv.tx = ((Integer)evt.arg).intValue();
  66.         cv.repaint();
  67.         return true;
  68.     }
  69.     return false;
  70.     }
  71.  
  72.     public static void main(String args[]) {
  73.     new ScrollbarTest();
  74.     }
  75. }
  76.